﻿<%@ Page Title="JUpdater" Language="C#" MasterPageFile="~/Controls.master" AutoEventWireup="true"
    CodeBehind="JUpdater.aspx.cs" Inherits="JQuery.WebKit.WebClient.JUpdaterControl" %>

<asp:Content ID="HeaderContent" runat="server" ContentPlaceHolderID="ContentPlaceHolderHead">
    <style type="text/css">
        .indent
        {
            padding-left: 10px;
        }
    </style>
    <script type="text/javascript">
        var stop = false;
        var tSimple = null;
        var t1 = null;
        var t2 = null;
        var t3 = null;
        var t4 = null;
        var t5 = null;
        $(document).ready(function () {
            tSimple = $('#' + '<%=lblWatchSimple.ClientID %>').stopWatch({ onDisplay: function (event, time, responseLength) {
                if (typeof responseLength != 'undefined') {
                    $('#' + '<%=lblWatchSimple.ClientID %>').html('Time: ' + time + ' (' + $.formatBytes(responseLength) + ')');
                }
                else {
                    $('#' + '<%=lblWatchSimple.ClientID %>').html('Time: ' + time + ' (unknown)');
                }
            }
            });
            t1 = $('#' + '<%=lblWatch1.ClientID %>').stopWatch({ onDisplay: function (event, time, responseLength) {
                if (typeof responseLength != 'undefined') {
                    $('#' + '<%=lblWatch1.ClientID %>').html('Time: ' + time + ' (' + $.formatBytes(responseLength) + ')');
                }
                else {
                    $('#' + '<%=lblWatch1.ClientID %>').html('Time: ' + time + ' (unknown)');
                }
            }
            });
            t2 = $('#' + '<%=lblWatch2.ClientID %>').stopWatch({ onDisplay: function (event, time, responseLength) {
                if (typeof responseLength != 'undefined') {
                    $('#' + '<%=lblWatch2.ClientID %>').html('Time: ' + time + ' (' + $.formatBytes(responseLength) + ')');
                }
                else {
                    $('#' + '<%=lblWatch2.ClientID %>').html('Time: ' + time + ' (unknown)');
                }
            }
            });
            t3 = $('#' + '<%=lblWatch3.ClientID %>').stopWatch({ onDisplay: function (event, time, responseLength) {
                if (typeof responseLength != 'undefined') {
                    $('#' + '<%=lblWatch3.ClientID %>').html('Time: ' + time + ' (' + $.formatBytes(responseLength) + ')');
                }
                else {
                    $('#' + '<%=lblWatch3.ClientID %>').html('Time: ' + time + ' (unknown)');
                }
            }
            });
            t4 = $('#' + '<%=lblWatch4.ClientID %>').stopWatch({ onDisplay: function (event, time, responseLength) {
                if (typeof responseLength != 'undefined') {
                    $('#' + '<%=lblWatch4.ClientID %>').html('Time: ' + time + ' (' + $.formatBytes(responseLength) + ')');
                }
                else {
                    $('#' + '<%=lblWatch4.ClientID %>').html('Time: ' + time + ' (unknown)');
                }
            }
            });
            t5 = $('#' + '<%=lblWatch5.ClientID %>').stopWatch({ onDisplay: function (event, time, responseLength) {
                if (typeof responseLength != 'undefined') {
                    $('#' + '<%=lblWatch5.ClientID %>').html('Time: ' + time + ' (' + $.formatBytes(responseLength) + ')');
                }
                else {
                    $('#' + '<%=lblWatch5.ClientID %>').html('Time: ' + time + ' (unknown)');
                }
            }
            });
        });

        var op = 'refresh';
        function stopUpdate() {
            stop = true;
            t1.stopTimer();
            t2.stopTimer();
            t3.stopTimer();
            t4.stopTimer();
            t5.stopTimer();
        }

        function startRefresh() {
            op = 'refresh';
            stop = false;
            t1.startTimer();
            t2.startTimer();
            t3.startTimer();
            t4.startTimer();
            t5.startTimer();
            $('#' + '<%=GetID(1) %>').jupdater('refresh');
        }

        function startSubmit() {
            op = 'submit';
            stop = false;
            t1.startTimer();
            t2.startTimer();
            t3.startTimer();
            t4.startTimer();
            t5.startTimer();
            $('#' + '<%=GetID(1) %>').jupdater('submit');
        }

        function setMilliseconds(request, index) {
            switch (index) {
                case 1:
                    t1.stopTimer(request.responseText.length);
                    t2.startTimer();
                    break;
                case 2:
                    t2.stopTimer(request.responseText.length);
                    t3.startTimer();
                    break;
                case 3:
                    t3.stopTimer(request.responseText.length);
                    t4.startTimer();
                    break;
                case 4:
                    t4.stopTimer(request.responseText.length);
                    t5.startTimer();
                    break;
                case 5:
                    t5.stopTimer(request.responseText.length);
                    t1.startTimer();
                    break;
            }
        }

        function updateComplete(event, request, textStatus, index) {
            switch (index) {
                case 1:
                    setMilliseconds(request, index);
                    if (stop == false) {
                        $('#' + '<%=GetID(2) %>').jupdater(op === 'refresh' ? 'refresh' : 'submit');
                    }
                    break;
                case 2:
                    setMilliseconds(request, index);
                    if (stop == false) {
                        $('#' + '<%=GetID(3) %>').jupdater(op === 'refresh' ? 'refresh' : 'submit');
                    }
                    break;
                case 3:
                    setMilliseconds(request, index);
                    if (stop == false) {
                        $('#' + '<%=GetID(4) %>').jupdater(op === 'refresh' ? 'refresh' : 'submit');
                    }
                    break;
                case 4:
                    setMilliseconds(request, index);
                    if (stop == false) {
                        $('#' + '<%=GetID(5) %>').jupdater(op === 'refresh' ? 'refresh' : 'submit');
                    }
                    break;
                case 5:
                    setMilliseconds(request, index);
                    if (stop == false) {
                        $('#' + '<%=GetID(1) %>').jupdater(op === 'refresh' ? 'refresh' : 'submit');
                    }
                    break;
            }
        }

        function beginUpdateSimple() {
            tSimple.startTimer();
        }
        function updateCompleteSimple(event, request, textStatus) {
            tSimple.stopTimer(request.responseText.length);
        }
        function updateErrorSimple(request, textStatus, errorThrown) {
            $('#' + '<%=lblWatchSimple.ClientID %>').html('Error ' + textStatus);
        }
        
    </script>
</asp:Content>
<asp:Content ID="Content1" ContentPlaceHolderID="DemoContent" runat="server">
    <webkit:JTab ID="demoTab" runat="server">
        <webkit:JTabItem ID="demoSimple" runat="server" Text="Simple Implementation">
            <table cellpadding="0" cellspacing="3" border="0" width="100%">
                <tr>
                    <th align="left">
                        Updater
                    </th>
                    <th align="left">
                        Roundtrip time
                    </th>
                </tr>
                <tr>
                    <td>
                        Simple Updater
                    </td>
                    <td>
                        <asp:Label ID="lblWatchSimple" runat="server"></asp:Label>
                    </td>
                </tr>
            </table>
            <hr />
            <table cellpadding="0" cellspacing="3" border="1" width="100%">
                <tr>
                    <th align="left">
                        Updater 1
                    </th>
                </tr>
                <tr>
                    <td class="indent">
                        <webkit:JUpdater ID="JUpdaterSimple" runat="server" OnBeginUpdate="beginUpdateSimple()"
                            OnComplete="updateCompleteSimple(event, request, textStatus)" OnError="updateErrorSimple(request, textStatus, errorThrown)">
                            <asp:Label ID="lblServerTimeSimple" runat="server"></asp:Label>
                            <hr />
                            <webkit:JButton ID="btnRefreshInnerSimple" runat="server" Text="Refresh from inside"
                                Behavior="Refresh">
                            </webkit:JButton>
                            <webkit:JButton ID="btnSubmitInnerSimple" runat="server" Text="Submit from inside" Behavior="Submit">
                            </webkit:JButton>
                        </webkit:JUpdater>
                    </td>
                </tr>
            </table>
            <div style="border: solid 1px blue">
                <webkit:JButton ID="btnRefreshOuterSimple" runat="server" TargetUpdater="JUpdaterSimple"
                    Text="Refresh from outside" Behavior="Refresh">
                </webkit:JButton>
                <webkit:JButton ID="btnSubmitOuterSimple" runat="server" Text="Submit from outside"
                    TargetUpdater="JUpdaterSimple" Behavior="Submit">
                </webkit:JButton>
            </div>
        </webkit:JTabItem>
        <webkit:JTabItem ID="demoCascade" runat="server" Text="Cascade Update">
            <table cellpadding="0" cellspacing="1" border="0" width="100%">
                <tr>
                    <th align="left">
                        Updater
                    </th>
                    <th align="left">
                        Roundtrip time
                    </th>
                </tr>
                <tr>
                    <td>
                        Updater 1
                    </td>
                    <td>
                        <asp:Label ID="lblWatch1" runat="server"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        Updater 2
                    </td>
                    <td>
                        <asp:Label ID="lblWatch2" runat="server"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        Updater 3
                    </td>
                    <td>
                        <asp:Label ID="lblWatch3" runat="server"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        Updater 4
                    </td>
                    <td>
                        <asp:Label ID="lblWatch4" runat="server"></asp:Label>
                    </td>
                </tr>
                <tr>
                    <td>
                        Updater 5
                    </td>
                    <td>
                        <asp:Label ID="lblWatch5" runat="server"></asp:Label>
                    </td>
                </tr>
            </table>
            <hr />
            <table cellpadding="0" cellspacing="1" border="1" width="100%">
                <tr>
                    <th align="left">
                        Updater 1
                    </th>
                </tr>
                <tr>
                    <td class="indent">
                        <webkit:JUpdater ID="JUpdater1" runat="server" OnComplete="updateComplete(event, request, textStatus, 1)">
                            <asp:Label ID="lblServerTime1" runat="server"></asp:Label>
                            <table cellpadding="0" cellspacing="1" border="1" width="100%">
                                <tr>
                                    <th align="left">
                                        Updater 2
                                    </th>
                                </tr>
                                <tr>
                                    <td class="indent">
                                        <webkit:JUpdater ID="JUpdater2" runat="server" OnComplete="updateComplete(event, request, textStatus, 2)">
                                            <asp:Label ID="lblServerTime2" runat="server"></asp:Label>
                                            <table cellpadding="0" cellspacing="1" border="1" width="100%">
                                                <tr>
                                                    <th align="left">
                                                        Updater 3
                                                    </th>
                                                </tr>
                                                <tr>
                                                    <td class="indent">
                                                        <webkit:JUpdater ID="JUpdater3" runat="server" OnComplete="updateComplete(event, request, textStatus, 3)">
                                                            <asp:Label ID="lblServerTime3" runat="server"></asp:Label>
                                                            <table cellpadding="0" cellspacing="1" border="1" width="100%">
                                                                <tr>
                                                                    <th align="left">
                                                                        Updater 4
                                                                    </th>
                                                                </tr>
                                                                <tr>
                                                                    <td class="indent">
                                                                        <webkit:JUpdater ID="JUpdater4" runat="server" OnComplete="updateComplete(event, request, textStatus, 4)">
                                                                            <asp:Label ID="lblServerTime4" runat="server"></asp:Label>
                                                                            <table cellpadding="0" cellspacing="1" border="1" width="100%">
                                                                                <tr>
                                                                                    <th align="left">
                                                                                        Updater 5
                                                                                    </th>
                                                                                </tr>
                                                                                <tr>
                                                                                    <td class="indent">
                                                                                        <webkit:JUpdater ID="JUpdater5" runat="server" OnComplete="updateComplete(event, request, textStatus, 5)">
                                                                                            <asp:Label ID="lblServerTime5" runat="server"></asp:Label>
                                                                                            <br />
                                                                                            Lorem ipsum dolor sit amet, consectetur adipiscing elit. Nullam porttitor tellus
                                                                                            nisl, at consectetur est. Curabitur consequat, lacus eget vestibulum pellentesque,
                                                                                            quam tortor viverra lorem, ac ullamcorper orci lacus vitae nibh. Suspendisse varius
                                                                                            tortor nec ipsum aliquet consectetur. Sed gravida sapien vel magna rhoncus sed rhoncus
                                                                                            augue dapibus. Maecenas ultrices commodo risus eu lobortis. Nunc porttitor blandit
                                                                                            dapibus. Maecenas tincidunt odio id augue placerat pretium. Proin gravida lacinia
                                                                                            pharetra. Praesent non sapien felis. Nunc sit amet ligula viverra tellus ornare
                                                                                            viverra vel sed purus. Nullam porttitor convallis elit a blandit. Proin malesuada
                                                                                            velit vel nisl euismod vel fringilla felis dapibus. Donec sit amet tellus mauris.
                                                                                            Nam eget nibh nec erat rhoncus porta in vitae augue. Curabitur fermentum lectus
                                                                                            quis mi eleifend vehicula volutpat lorem lobortis. Aenean tincidunt varius urna,
                                                                                            in tristique enim dapibus et. Donec eu risus quis tortor euismod pretium at luctus
                                                                                            dui. Maecenas sagittis dui a est rhoncus placerat. Fusce ac tortor a tellus bibendum
                                                                                            aliquam. Mauris et nisl quis odio egestas auctor. Lorem ipsum dolor sit amet, consectetur
                                                                                            adipiscing elit. Duis et libero mauris. Sed in tellus enim. Nunc pellentesque laoreet
                                                                                            nulla id laoreet. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Duis
                                                                                            elit quam, ultrices sed suscipit sed, mollis mollis augue. Lorem ipsum dolor sit
                                                                                            amet, consectetur adipiscing elit. Class aptent taciti sociosqu ad litora torquent
                                                                                            per conubia nostra, per inceptos himenaeos. Duis porttitor neque iaculis nisl congue
                                                                                            scelerisque eu ac est. Fusce ut euismod libero. Sed pellentesque volutpat eros,
                                                                                            id pellentesque ipsum dapibus eu. Praesent eu fringilla nunc. Curabitur tincidunt
                                                                                            lobortis sapien ac accumsan. Nullam id lorem nibh. Aliquam at augue neque. Cras
                                                                                            nec purus sit amet augue pulvinar porta. Pellentesque adipiscing ante eu magna gravida
                                                                                            consequat consectetur lectus tempor. Aliquam at neque massa, vitae pretium nibh.
                                                                                            Cum sociis natoque penatibus et magnis dis parturient montes, nascetur ridiculus
                                                                                            mus.
                                                                                        </webkit:JUpdater>
                                                                                    </td>
                                                                                </tr>
                                                                            </table>
                                                                        </webkit:JUpdater>
                                                                    </td>
                                                                </tr>
                                                            </table>
                                                        </webkit:JUpdater>
                                                    </td>
                                                </tr>
                                            </table>
                                        </webkit:JUpdater>
                                    </td>
                                </tr>
                            </table>
                        </webkit:JUpdater>
                    </td>
                </tr>
            </table>
            <div style="border: solid 1px blue">
                <webkit:JButton ID="btnRefresh" runat="server" TargetUpdater="JUpdater1" Text="Refresh"
                    Behavior="Refresh" OnClientClick="startRefresh();">
                </webkit:JButton>
                <webkit:JButton ID="btnSubmit" runat="server" Text="Submit" TargetUpdater="JUpdater1"
                    Behavior="Submit" OnClientClick="startSubmit();">
                </webkit:JButton>
                <webkit:JButton ID="btnStopUpdate" runat="server" Text="Stop" Behavior="None" OnClientClick="stopUpdate();">
                </webkit:JButton>
            </div>
        </webkit:JTabItem>
        <webkit:JTabItem ID="demoDeferLoad" runat="server" Text="Defer Load">
        </webkit:JTabItem>
    </webkit:JTab>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="DescriptionContent" runat="server">
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="PropertiesCSharpContent" runat="server">
<%--    <web:SyntaxHighlighter ID="synProps" runat="server" Brush="CSharp" EnclosingType="Pre" Toolbar="false">
        private string A {get; set;}
    </web:SyntaxHighlighter>
--%></asp:Content>
<asp:Content ID="Content9" ContentPlaceHolderID="PropertiesJSContent" runat="server">
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="EventsCSharpContent" runat="server">
</asp:Content>
<asp:Content ID="Content10" ContentPlaceHolderID="EventsJSContent" runat="server">
</asp:Content>
<asp:Content ID="Content5" ContentPlaceHolderID="MethodsCSharpContent" runat="server">
</asp:Content>
<asp:Content ID="Content11" ContentPlaceHolderID="MethodsJSContent" runat="server">
</asp:Content>
<asp:Content ID="Content6" ContentPlaceHolderID="CreditsContent" runat="server">
</asp:Content>
<asp:Content ID="Content7" ContentPlaceHolderID="IssuesContent" runat="server">
</asp:Content>
<asp:Content ID="Content8" ContentPlaceHolderID="CommentsContent" runat="server">
</asp:Content>
